<?php 
namespace app\user\controller;
use app\common\controller\Api;
use app\user\traits\controllers\TraitUser;
use think\Loader;
use think\Session;
use think\Request;
/**
 * 会员消息类
 */
class Message extends Api
{
	use TraitUser;
	const READ_STATUS = 1;
	const NOT_READ_STATUS = 0;

	protected $beforeActionList = [
        'checkLogin'
    ];
    /**
     * [checkLogin 判断是否登陆]
     * @return [type] [description]
     */
    protected function checkLogin()
    {
        if (!model('Users')->checkLogin()) {
            Session::set('redirect_url', Request::instance()->url(true));
            $this->redirect('@user/login');
            exit;
        }
    }

	/**
	 * 消息列表
	 */
	public function getIndex(){
		$msgRead = $this->getNoticeCount(self::READ_STATUS);
		$msgNotRead = $this->getNoticeCount(self::NOT_READ_STATUS);
		$msgAll = $msgRead + $msgNotRead;
		$list = $this->getNoticeList();
		return view('user_message/index',['list' => $list,'msgAll'=>$msgAll,'msgNotRead'=>$msgNotRead]);
	}
	
	/**
	 * 删除消息
	 */
	public function getDel(){
		 if($this->delNotice(input('get.id'))){
		 	$this->success(lang('delete message success'),'/message/index');
		 }
		 $this->error(lang('delete message error'));
	}
	
	/**
	 * 设置消息状态
	 */
	public function postSetStatus(){
		if(Loader::model('Users')->readNotice($this->request->post('id'))){
			return json(true);
		}
		return json(false);
	}
}


 ?>